﻿using System;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Linq;

namespace _041_改变数据协定成员的序列化顺序
{
    class Program
    {
        static void Main(string[] args)
        {
            using (FileStream 序列化操作=new FileStream("zoomla.xml",FileMode.Create))
            {
                默认表 操作 = new 默认表
                {
                    PropA = 3,
                    PropB = 15,
                    PropC = 10000L,
                    PropD = "zoomlaCMS"
                };
                DataContractSerializer 可以 = new DataContractSerializer(typeof(默认表));
                可以.WriteObject(序列化操作, 操作);
            }

            using (FileStream 输出xml=new FileStream("zoomla.xml",FileMode.Open))
            {
                XDocument 来吧宝宝 = XDocument.Load(输出xml);
                Console.Write("默认表 实例化序列化后生成的XML文档：\n" + 来吧宝宝);
            }

        }
    }

    [DataContract]
    public class 默认表
    {
        [DataMember(Order =2)]
        public string PropD { get; set; }
        [DataMember(Order =0)]
        public long PropC { get; set; }
        [DataMember(Order = 1)]
        public int  PropB { get; set; }
        [DataMember(Order = 3)]
        public short PropA { get; set; }
    }
}
